package com.yumeng.common.data.enums;

import com.yumeng.common.exception.YumengException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author wxd
 * @date 2021/12/14 10:08
 */
@Getter
@AllArgsConstructor
public enum YnFlag implements BaseEnum {

    Y(1, "是", true),
    N(0, "否", false);

    private final Integer code;
    private final String desc;
    private final Boolean val;

    public static String descValueOf(Integer code){
        for (YnFlag yn : YnFlag.values()){
            if (yn.getCode().equals(code)){
                return yn.getDesc();
            }
        }
        throw new YumengException("Y/N值异常：" + code);
    }

    public static Boolean boolValueOf(Integer code){
        for (YnFlag yn : YnFlag.values()){
            if (yn.getCode().equals(code)){
                return yn.getVal();
            }
        }
        throw new YumengException("Y/N值异常：" + code);
    }

    public static Integer getYCode(){
        return YnFlag.Y.getCode();
    }

    public static Integer getNCode(){
        return YnFlag.N.getCode();
    }
}
